<template>
  <div class="category-wrapper">
    <van-tabs v-model="active" @change="onChange" color="#FFFFFF" background="#FF6933" title-inactive-color="#ffffff" title-active-color="#ffffff">
      <van-tab v-for="item in categoryData" :key="item.id" :title="item.name"></van-tab>
    </van-tabs>
    <div class="btn-screen">
      <div class="img-box" @click="show = !show">
        <van-icon name="filter-o" />
      </div>
    </div>

    <van-popup v-model="show" position="bottom" :style="{ height: '25%' }" >
      <div class="column-box">
        <div class="column">
          <div class="column-l">
            类型：
          </div>
          <div class="column-r">
            <p :class="where.is_tmall === true? 'red-bottom-line': ''" @click="where.is_tmall = !where.is_tmall">天猫商品</p>
            <p :class="where.is_tmall === false? 'red-bottom-line': ''" @click="where.is_tmall = !where.is_tmall">不限</p>
          </div>
        </div>
        <div class="column">
          <div class="column-l">
            优惠券：
          </div>
          <div class="column-r">
            <p :class="where.has_coupon === true? 'red-bottom-line': ''" @click="where.has_coupon = !where.has_coupon">有</p>
            <p :class="where.has_coupon === false? 'red-bottom-line': ''" @click="where.has_coupon = !where.has_coupon">不限</p>
          </div>
        </div>
        <div class="column">
          <div class="column-l">
            折扣价：
          </div>
          <div class="column-r">
            <input type="number" placeholder="¥" v-model="where.start_price"> ~
            <input type="number" placeholder="¥" v-model="where.end_price">
          </div>
        </div>
        <div class="column">
          <div class="column-l">
            综合排序：
          </div>
          <div class="column-r">
            <p :class="where.sort === 'total_sales_des'? 'red-bottom-line': ''" @click="where.sort = 'total_sales_des'">销量</p>
            <p :class="where.sort === 'price_des'? 'red-bottom-line': ''" @click="where.sort = 'price_des'">价格</p>
            <p :class="where.sort === 'tk_total_sales_des'? 'red-bottom-line': ''" @click="where.sort = 'tk_total_sales_des'">推广量</p>
          </div>
        </div>
      </div>
    </van-popup>
  </div>
</template>

<script>
import Vue from 'vue';
import { Popup } from 'vant';

Vue.use(Popup);
import { getAllCategory } from '@/api/category';
export default {
  name: "category",
  data() {
    return {
      active: 0,
      show: false,
      categoryData: [],
      where: {
        category_id: '', //类别ID(多个逗号隔开)
        is_tmall: false, //商品筛选-是否天猫商品。true表示属于天猫商品，false或不设置表示不限
        has_coupon: true, //优惠券筛选-是否有优惠券。true表示该商品有优惠券，false或不设置表示不限
        start_price: '', //商品筛选-折扣价范围下限。单位：元
        end_price: '', //商品筛选-折扣价范围上限。单位：元
        need_free_shipment: false, //商品筛选-是否包邮。true表示包邮，false或不设置表示不限
        sort: '', //排序_des（降序），排序_asc（升序），销量（total_sales），淘客佣金比率（tk_rate）， 累计推广量（tk_total_sales），总支出佣金（tk_total_commi），价格（price）
      }
    };
  },
  mounted () {
    getAllCategory().then(res => {
      this.categoryData = res
    });
  },
  methods: {
    onChange(index) {
      this.where.category_id = this.categoryData[index].category_id;
    },
  },
  watch:{
    where: {
      handler: function (value) {
        console.log('caregory', value)
        this.$emit('where', value);
      },
      deep: true
    }
  }
}
</script>

<style scoped>
.btn-screen{
  position: relative;
  z-index: 99;
}
.btn-screen .img-box{
  width: 24px;
  height: 24px;
  background: #FF6933;
  position: absolute;
  top:-15px;
  right:5px;
  border-bottom-left-radius: 50%;
  border-bottom-right-radius: 50%;
  overflow: hidden;
  text-align: center;
}
.btn-screen .img-box .van-icon{
  margin-top:5px;
  color: white;
}
.column-box{
  padding:15px;
}
.column-box .column{
  display: flex;
  justify-content: flex-start;
  user-select:none;
  padding: 3px 3px;
  line-height: 24px;
  font-size: 14px;
  border-bottom:1px solid #EEEEEE;
}
.column-box .column .column-l{
  width: 80px;
}
.column-box .column .column-r{
  display: flex;
  justify-content: flex-start;
}
.column-box .column .column-r p{
  margin-right: 15px;
  cursor:pointer;
  background: #EEEEEE;
  padding:3px 10px;
  border-radius: 5px;
}
.column-box .column .column-r input{
  width: 55px;
  height: 18px;
  border:1px solid #EEEEEE;
  border-radius: 3px;
}
.red-bottom-line{
  color: #EE0A24;
  background: #FDE7EA!important;
}

</style>